import { defineStore } from 'pinia'
import IProjects from '../interface/IProjects'
import { storage } from '../utils'
export default defineStore('projectsStore', {
  state: () => ({
    projects: [] as IProjects[],
  }),
  actions: {
    loadState() {
      const data = storage.get('CURRENT_PROJECTS', '[]');
      this.$patch({ projects: JSON.parse(data) });
    },

    setAllState(newState: Partial<IProjects[]>) {
      storage.set('CURRENT_PROJECTS', JSON.stringify(newState))
      this.$patch({ projects: newState });
    },
    getAllState(): IProjects[] {
      this.loadState();
      return this.projects;
    },
  },
})
